var pic = '../AnLi/img/1.jpg'
var vm = new Vue({
    el: '#app',
    data: {//负责定义响应数据
        list: [
            { pic, name: '秋刀鱼', price: 35.00, count: 0 },
            { pic, name: '椒盐蘑菇', price: 45.00, count: 0 },
            { pic, name: '红烧鲤鱼', price: 85.00, count: 0 }
        ]
    },
    methods: {//负责定义方法
        add(item) {
            item.count++;
        },
        sub(item) {
            if (item.count > 0)
                item.count--;
        },
        clean() {
            this.list = [];
        }
    },
    computed: {//负责定义计算属性
        //写法一
        totalCount() {
            var sum = 0;
            this.list.forEach((item) => {
                sum += item.count;
            })
            return sum;
        },
        //写法二
        totalPrice: {
            get() {
                var sum = 0;
                this.list.forEach((item) => {
                    sum += item.count * item.price;
                })
                return sum;
            }
        }
    }
})